// import { defineStore } from 'pinia';
// import * as fApi from '@/api/flow/flow';
// import FlowRuntimeApi from '@/api/flow/FlowRuntimeApi';
// import { mapProcessGroup } from '@/api/flow/flow';
// import Utils from '@/utils/flow/utils/Common';
//
// export const useChatStore = defineStore('useChatStore', {
//   state: () => ({
//     processors: [],
//     links: [],
//     groups: [],
//     flowGroupIDs: ['root'],
//     allFlow: [],
//     currentFlow: {},
//     currentClickNode: {}
//   }),
//   getters: {
//     flowGroupId (state) {
//       return state.flowGroupIDs[state.flowGroupIDs.length - 1];
//     },
//     processors (state) {
//       return state.processors;
//     },
//     links (state) {
//       return state.links;
//     },
//     allFlow (state) {
//       return state.allFlow;
//     },
//     getCurrentFlow (state) {
//       return state.currentClickNode;
//     },
//     getCurrentNode (state) {
//       return state.currentFlow;
//     },
//     getGroups (state) {
//       return state.groups;
//     }
//   },
//   actions: {
//     async loadAllFlow (callback) {
//       await new FlowRuntimeApi().GetAllFlowFiles((allFlow) => {
//         this.allFlow = allFlow;
//         if (Utils.IsEmpty(this.currentFlow)) {
//           this.currentFlow = allFlow[0];
//         }
//         callback(allFlow);
//       });
//     },
//     async getProcessGroup () {
//       const flowGroupId = this.flowGroupId;
//       new FlowRuntimeApi().GetCurrentFlow(null, (updating) => {
//         if (Utils.IsEmpty(updating)) {
//           return null;
//         }
//         const ssss = Utils.GetParents(updating);
//         const updated = mapProcessGroup(ssss);
//         this.processors = updated.processors;
//         this.links = updated.links;
//         this.groups = updated.groups;
//         if (flowGroupId === 'root') {
//           this.flowGroupIDs = [updated.id];
//         }
//       });
//     },
//     setProcessGroup (updated) {
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//     },
//     async newProcessor ({ typeId, x, y, maxX, maxY }) {
//       const flowGroupId = this.flowGroupId;
//       const updated = await fApi.createProcessor(typeId, { x, y, maxX, maxY }, flowGroupId);
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//     },
//     async UpdateSnippet (payload) {
//       const flowGroupId = this.flowGroupId;
//       const processors = this.processors.filter(p => payload.processors.includes(p.id));
//       const groups = this.groups.filter(p => payload.groups.includes(p.id));
//       const updated = await fApi.UpdateSnippet(processors, groups, flowGroupId);
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//     },
//     async newConnection (link) {
//       const flowGroupId = this.flowGroupId;
//       const updated = await fApi.createConnection(link, flowGroupId);
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//     },
//     async cloneSnippet (payload) {
//       const flowGroupId = this.flowGroupId;
//       const oldids = this.processors.map(p => p.id);
//       const processors = this.processors.filter(p => payload.processors.includes(p.id));
//       const links = this.links.filter(l => payload.links.includes(l.id));
//       const updated = await fApi.cloneSnippet({ processors, links }, flowGroupId);
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//       return updated.processors.filter(p => !oldids.includes(p.id)).map(p => p.id);
//     },
//     async addGroup (payload) {
//       const flowGroupId = this.flowGroupId;
//       const processors = this.processors.filter(p => payload.processors.includes(p.id));
//       const links = this.links.filter(link => payload.links.includes(link.id));
//       const updated = await fApi.addGroup({ processors, links }, flowGroupId);
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//     },
//     async remvoeSnippet ({ processors, links, groups }) {
//       const flowGroupId = this.flowGroupId;
//       const updated = await fApi.deleteSnippet({ processors, links, groups }, flowGroupId);
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//     },
//     async ungroup (groupID) {
//       const flowGroupId = this.flowGroupId;
//       const updated = await fApi.ungroup(groupID, flowGroupId);
//       this.processors = updated.processors;
//       this.links = updated.links;
//       this.groups = updated.groups;
//     },
//     async enterGroup (groupID) {
//       const { flowGroupIDs } = this;
//       const index = flowGroupIDs.findIndex(id => id === groupID);
//       if (index < 0) {
//         this.flowGroupIDs = [...flowGroupIDs, groupID];
//       } else {
//         this.flowGroupIDs = flowGroupIDs.slice(0, index + 1);
//       }
//       await this.getProcessGroup();
//     }
//   }
// });
